package edu.pku.sei.transformation.editor.controller.commands.link;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.transformation.editor.model.test.CheckPoint;
import edu.pku.sei.transformation.editor.model.test.CheckPointOperand;

public class CheckPointOperandCreateCommand
		extends
		AbstractLinkCreateCommand<CheckPointOperand, CheckPoint, MetaModelElement> {

	public CheckPointOperandCreateCommand(CheckPointOperand link,
			CheckPoint source) {
		super(link, source);
		this.setLabel("create checkpoint connection");
	}

	@Override
	public boolean canExecute() {
		if (source != null && source.canAddOperand())
			return super.canExecute();
		else
			return false;
	}

	@Override
	public void execute() {
		link.setCheckPoint(source);
		link.setOperand(target);
		source.addOperand(link);
	}

	@Override
	public void undo() {
		link.setCheckPoint(null);
		link.setOperand(null);
		source.removeOperand(link);
	}

}
